home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1.5 KB | 88 lines | [TEXT/CWIE] |
- // Application.cp
-
- #ifndef Application_h
- #include "Application.h"
- #endif
- #ifndef EventQueue_h
- #include "EventQueue.h"
- #endif
- #ifndef RootFocus_h
- #include "RootFocus.h"
- #endif
- #ifndef Event_h
- #include "Event.h"
- #endif
- #ifndef Process_h
- #include "Process.h"
- #endif
- #ifndef UserState_h
- #include "UserState.h"
- #endif
- #ifndef UserCancelledError_h
- #include "UserCancelledError.h"
- #endif
- #ifndef BroadcastLoop_h
- #include "BroadcastLoop.h"
- #endif
-
- Application *Application::the = 0;
-
- Application::Application()
- : CommandHandler<Quitting>( RootFocus::The() ),
- quitting( false )
- {
- Assert( the == 0 );
- the = this;
- }
-
- Application::~Application()
- {
- if ( RootFocus::The().Active() )
- RootFocus::Deactivate();
- }
-
- void Application::Run()
- {
- EventManagerUser();
- if ( Process::Application() == Process::Front() )
- RootFocus::Activate();
-
- UserState::The().Announce();
-
- EventQueue& queue( EventQueue::The() );
-
- for ( queue++; !quitting; queue++ )
- {
- Event& event( MakeEvent( *queue ) );
-
- while ( event.CanAppend() )
- {
- queue.AdvanceWithoutWaiting();
- if ( !event.Append( *queue ) )
- {
- queue--;
- break;
- }
- }
-
- event.Respond();
- }
- }
-
- bool Application::CanQuit() const
- {
- return true;
- }
-
- void Application::Quit( SavingOption savingOption )
- {
- for ( BroadcastLoop<PreparingToQuit> receiver( *this );
- receiver.Unfinished();
- receiver++ )
- receiver->PrepareToQuit( savingOption );
-
- quitting = true;
- }
-
- #include "BroadcastLoop.cp"
-